using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using Watchdog.Bll;

namespace Watchdog {
    public class DispatcherService : IDispatcher {

        #region IDispatcher Members

        public void Subscribe () {
            Log.Write (Severity.Info, "A testunit subscribed");
        }

        public void Unsubscribe () {
            Log.Write (Severity.Info, "A testunit unsubscribed");
        }

        public void SetOnline ( Facade.TestUnit unit ) {
            Log.Write (Severity.Info, "TestUnit '" + unit.Name + "' from farm '" + unit.Zone + "' is available.");
            //IDispatchStatusHandler caller = OperationContext.Current.GetCallbackChannel<IDispatchStatusHandler> ();
            //foreach (TestUnit testunit in Context.Current.ScheduleEngine.DmzTestUnits) {
            //    if (testunit.Name.ToUpper () == hostname.ToUpper ()) {
            //        testunit.Online = true;
            //        Context.Current.ClientsByConnection[caller] = testunit;
            //        Context.Current.ClientsByTestUnit.Add ( testunit, caller );
            //        return;
            //    }
            //}
            //foreach (TestUnit testunit in Context.Current.ScheduleEngine.InternetTestUnits) {
            //    if (testunit.Name.ToUpper () == hostname.ToUpper ()) {
            //        testunit.Online = true;
            //        Context.Current.ClientsByConnection[caller] = testunit;
            //        Context.Current.ClientsByTestUnit.Add ( testunit, caller );
            //        return;
            //    }
            //}
            //foreach (TestUnit testunit in Context.Current.ScheduleEngine.IntranetTestUnits) {
            //    if (testunit.Name.ToUpper () == hostname.ToUpper ()) {
            //        testunit.Online = true;
            //        Context.Current.ClientsByConnection[caller] = testunit;
            //        Context.Current.ClientsByTestUnit.Add ( testunit, caller );
            //        return;
            //    }
            //}
        }

        public void SetOffline ( Facade.TestUnit unit ) {
            //throw new Exception ("The method or operation is not implemented.");
            Log.Write (Severity.Info, "TestUnit '" + unit.Name + "' from farm '" + unit.Zone + "' is unavailable.");
        }

        #endregion
    }
}
